package com.example.demo.pattern.factorypattern.pizza;

import com.example.demo.pattern.factorypattern.ingredient.IngredientFactory;

public class NYPizzaStore extends PizzaStore {

    //书中是把原料工厂放在Pizza里，实现使用不同原料工厂时，生产出来的披萨会被原料工厂影响，但感觉现实中一家店只会对应一个原料工厂吧？类似一个中央厨房
    public NYPizzaStore(IngredientFactory ingredientFactory) {
        this.ingredientFactory = ingredientFactory;
    }

    @Override
    public Pizza createPizza(String type) {
        Pizza pizza;
        switch (type) {
            case "NY":
                pizza = new NYPizza();
                break;
            default:
                throw new RuntimeException("Pizza type not exist");
        }
        pizza.setDough(ingredientFactory.createDough());
        pizza.setSauce(ingredientFactory.createSauce());

        pizza.bake();
        pizza.cut();

        return pizza;
    }
}
